package com.eqdd.yiqidian.ui.mine.pizhun.Fragment;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.RecyclerViewFragmentCustom;
import com.eqdd.yiqidian.adapter.recycleadapter.ItemClickSupport;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.BaseFragment;
import com.eqdd.yiqidian.bean.rebuild.LizhiPizhunListResultBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.utils.GreenDaoUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.List;

public class TestFragment extends BaseFragment {
    RecyclerViewFragmentCustom dataBinding;
    private SlimAdapterEx slimAdapterEx;

    @Override
    protected void setView() {
        slimAdapterEx = SlimAdapterEx.create().register(R.layout.list_item_01, new SlimInjector<LizhiPizhunListResultBean>() {
            @Override
            public void onInject(LizhiPizhunListResultBean data, IViewInjector injector) {
            }
        })
                .attachTo(dataBinding.recyclerView);
        ItemClickSupport.addTo(dataBinding.recyclerView)
                .setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
                    @Override
                    public void onItemClicked(RecyclerView recyclerView, int position, View v) {

                    }
                });
        OkGo.<HttpResult<List<LizhiPizhunListResultBean>>>post(HttpConfig.BASE_URL + HttpConfig.LIZHI_SHENPI_LIST)
                .params("step", GreenDaoUtil.getUser().getStep())
                .params("companyId", GreenDaoUtil.getUser().getCompanyId())
                .params("userGuid", GreenDaoUtil.getUser().getGuid())
                .execute(new DialogCallBack<HttpResult<List<LizhiPizhunListResultBean>>>((BaseActivity) getActivity()) {
                    @Override
                    public void onSuccess(Response<HttpResult<List<LizhiPizhunListResultBean>>> response) {
                        HttpResult<List<LizhiPizhunListResultBean>> httpResult = response.body();
                        ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            slimAdapterEx.updateData(httpResult.getItems());
                        }
                    }
                });
    }

    @Override
    protected void initData() {

    }


    @Override
    public ViewDataBinding initBinding(LayoutInflater inflater) {
        return dataBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_cool_recycler_view, null, false);

    }

    @Override
    public void onClick(View v) {

    }
}
